/*
 * Application Name: 工作票信息管理系统
 * Desc: 工作票草稿
 * Author: Albert 
 * Date: 2009-07-26
 */

Ext.extend(workpaper.baseModule,{	
	
    init: function(){
    	this.ds = new workpaper.store.dealPaper.draftStore();	 
    	this.ds.load();   	 	
	    /*
	    this.myData = [['ZS20090719235411001', '待签发', '热力机械工作票', '已填写','2009年7月20日 12:00～2009年7月20日 19:00', '文珠穆','2009/07/20 15:18:09', '检修部', '小郭'], ['ZS20090719235411002', '待签发', '热控工作票', '已填写','2009年7月21日 12:00～2009年7月21日 19:00', '文珠穆', '2009/07/20 15:18:09','检修部', '小郭']];
	    this.ds = new Ext.data.SimpleStore({
	        fields: [
	        {name: 'paperId'},
	        {name: 'waitingType'},
	        {name: 'paperType'},
	        {name: 'paperStatus'},
	        {name: 'planTime'},
	        {name: 'principal'},
	        {name: 'arriveTime'},
	        {name: 'workDept'},
	        {name: 'transactor'}                    
	        ]
	    });
	    this.ds.loadData(this.myData);
	    */	        	    
	    this.cm = new Ext.grid.ColumnModel([{
	           id: 'paperId',
	           header: "工作票编号",
	           dataIndex: 'paperId',
	           width: 70,
	           align: 'center',
	           hidden: false,
	           sortable: true,
	           renderer: this.gotoDealPaper 
	        },{
	           id: 'paperType',
	           header: "工作票类型",
	           dataIndex: 'paperType',
	           width: 70,
	           align: 'center',
	           hidden: false,
	           sortable: true
	           //renderer: app.dealPaper.waitingPaper.Renderers.topic           
	        },{
	           id: 'principal',
	           header: "工作负责人",
	           dataIndex: 'principal',
	           width: 70,
	           align: 'center',
	           hidden: false,
	           sortable: true
	           //renderer: app.dealPaper.waitingPaper.Renderers.topic           
	        },{
	           id: 'workUnit',
	           header: "工作班组",
	           dataIndex: 'workUnit',
	           width: 70,
	           align: 'center',
	           hidden: false,
	           sortable: true
	           //renderer: app.dealPaper.waitingPaper.Renderers.topic           
	        },{
	           id: 'workDept',
	           header: "工作部门",
	           dataIndex: 'workDept',
	           width: 70,
	           align: 'center',
	           hidden: true,
	           sortable: true
	           //renderer: app.dealPaper.waitingPaper.Renderers.topic           
	        },{
	           id: 'creator',
	           header: "创建人",
	           dataIndex: 'creator',
	           width: 70,
	           align: 'center',
	           hidden: false,
	           sortable: true
	           //renderer: app.dealPaper.waitingPaper.Renderers.topic           
	        },{
	           id: 'planTime',
	           header: "计划工作时间段",
	           dataIndex: 'planTime',
	           width: 70,
	           align: 'center',
	           hidden: false,
	           sortable: true
	           //renderer: app.dealPaper.waitingPaper.Renderers.topic           
	        },{
	           id: 'createTime',
	           header: "创建时间",
	           dataIndex: 'createTime',
	           width: 70,
	           align: 'center',
	           hidden: false,
	           sortable: true
	           //renderer: app.dealPaper.waitingPaper.Renderers.topic           
	        },{
	           id: 'paperStatus',
	           header: "工作票状态",
	           dataIndex: 'paperStatus',
	           width: 70,
	           align: 'center',
	           hidden: true,
	           sortable: true
	           //renderer: app.dealPaper.waitingPaper.Renderers.topic 
	        }        
	        ]);
	    this.cm.defaultSortable = true;	    
        this.sm = new Ext.grid.RowSelectionModel({
            singleSelect:true
            /*
            listeners: {
                selectionchange: function(sel){
                    var rec = sel.getSelected();
                    if(rec){
                        Ext.getCmp('preview').body.update('<b><u>' + rec.get('title') + '</u></b><br /><br />Post details here.');
                    }
                }
            }
            */
        });		

        this.draftPanel = new Ext.grid.GridPanel({
        	layout:'fit',	                
            stripeRows:true,
            columnLines : true,
            autoWidth : true, 	                
            id:'main-grid_m102',	                
            store: this.ds,
            cm: this.cm,
            sm: this.sm,
            //trackMouseOver:false,
            viewConfig: {
                forceFit:true,
                enableRowBody:true,
                showPreview:true
            },
            bbar: new Ext.PagingToolbar({
            	id: 'pageable_btn_m102',	                	
                pageSize: 25,
                store: this.ds,
                displayInfo: true,
                displayMsg: '当前用户的工作票草稿：第 {0} 至第 {1} 条， 共 {2} 条记录'	                    
            })
        });
	       	
        this.tab.add(this.draftPanel);        
        this.tab.doLayout();             
    },
    
    destroy: function(){
    	this.togglePreview = null;    	
		Ext.destroy(this.ds,
					this.cm,
					this.sm,
					Ext.getCmp("pageable_btn_m102"),					
					this.draftPanel
		);
		this.init = null;
    }, 
    
    gotoDealPaper : function(val){
    	return '<a href="#" onclick="alert(\'将新建一个tab跳转到对应工作票的处理页面\')">' + val + '</a>';
    }
}); 
